package com.gegao.somethinginteresting.adapter.viewpagerAdapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.facebook.drawee.view.SimpleDraweeView;
import com.gegao.somethinginteresting.utils.fresco.FrescoUtils2;

import java.util.List;

/**
 * Created by zhangzhanzhong on 2016/03/15.
 */
public class FlushAdapter extends PagerAdapter {

    private Context mContext;
    private List<Integer> imagesList;

    public FlushAdapter(Context mContext, List<Integer> imagesList) {
        this.mContext = mContext;
        this.imagesList = imagesList;
    }

    @Override
    public int getCount() {
        return imagesList.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        SimpleDraweeView simpleDraweeView = new SimpleDraweeView(mContext);
        simpleDraweeView.setAspectRatio(1.33f);
        simpleDraweeView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
        FrescoUtils2.load(simpleDraweeView).url(imagesList.get(position)).build();
        container.addView(simpleDraweeView);
        return simpleDraweeView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }


    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
}
